package gizmoball;


import gizmoball.Game.AnimationWindow;

import java.awt.*;


public class Tunnel {
	    private Color color = new Color(102,102,102);
	    private static int WIDTH = 30;//The width of the Tunnel
	    private static int MARGIN = 5; //The margin of the Tunnel to the board
	    private static int XLONG = 100; //The Long of Tunnel x
	    private static int YLONG = 300; //The Long of Tunnel y
	    private int upLineY;
	    private int downLineY;
	    private int leftLineX;
		private int rightLineX;
		private int minX;
		private int maxY;
	    
	    private AnimationWindow win;
		
	    
	    public Tunnel(AnimationWindow win)
	    {
	    	this.win = win;
	    }
	    


	    public void paint(Graphics g) {

	        // the "clip rectangle" is the area of the screen that needs to be
	        // modified
	   

	        // For this tiny program, testing whether we need to redraw is
	        // kind of silly.  But when there are lots of objects all over the
	        // screen this is a very important performance optimization   
	    	
	           g.setColor(color);
	           
	           this.upLineY = MARGIN;
		       this.downLineY = MARGIN + WIDTH;
		       this.leftLineX = this.win.getWidth()- MARGIN - WIDTH;
			   this.rightLineX = this.win.getWidth()- MARGIN;
		       this.minX = rightLineX - XLONG;
		       this.maxY = upLineY + YLONG;
	         
	           g.fillRect(leftLineX, downLineY, 3, YLONG-WIDTH);  //Left Line
	           g.fillRect(rightLineX, upLineY , 3, YLONG);   //Right Line
	           g.fillRect(minX, downLineY, XLONG-WIDTH ,3);     //Down Line
	           g.fillRect(minX, upLineY , XLONG, 3);     //Up Line
	    }
	    
	    

	    public int collision(int x, int y, int radius) {
	    	if(y <= maxY && y >= upLineY 
	    			&& x + radius > rightLineX)
	    	{
	    		x = rightLineX - radius;
	    		return 270;
	    	}
	    	else if (x >= minX  && x <= rightLineX  
	    			&& y-radius < upLineY )
	    	{
	    		y = upLineY + radius;
	    		return 180;
	    	}
	    	else if (y <= maxY && y >= downLineY  
	    			&& x > leftLineX && x-radius < leftLineX)
	    	{
	    		x = leftLineX + radius;
	    		return 90;
	    	}
	    	else if (x >= minX  && x <= leftLineX  
	    			&& y < downLineY && y+radius > downLineY)
	    	{
	    		y = downLineY - radius;
	    		return 0;
	    	} 	
	    	else 
	    		return -1;
	    }

			
	   


}
